<template>
  <div class="page">
    <!-- 搜索区域 开始 -->
    <div class="el_card_box">
      <el-form :inline="true" size="small" :model="formInline" class="search_form">
        <el-form-item label="发送状态：">
          <el-select v-model="formInline.sendStatus" clearable>
            <el-option label="发送中" value="1"></el-option>
            <el-option label="成功" value="3"></el-option>
            <el-option label="失败" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="时间筛选：">
          <el-date-picker v-model="formInline.orderTime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="客户信息：">
          <el-input v-model="formInline.customerTerm" placeholder="姓名/电话"></el-input>
        </el-form-item>
      </el-form>
      <div class="search_btn_box">
        <el-button type="primary" size="small" @click="onSearch">筛选</el-button>
        <el-button type="default" size="small" @click="rest">清空筛选</el-button>
      </div>
    </div>
    <!-- 搜索区域 end -->

    <!-- 表格 开始 -->
    <div class="table_box">
      <el-table ref="elTable" class="el_table" size="small" :data="tableData">
        <el-table-column prop="settleRegisterCnt" label="姓名/电话" width="150">
          <template slot-scope="{row}">
            {{ row.customerPhone }}
          </template>
        </el-table-column>
        <el-table-column prop="bizType" label="短信类型" show-overflow-tooltip>
          <template slot-scope="{row}">{{ bizTypeList[row.bizType] }}</template>
        </el-table-column>
        <el-table-column prop="sendTime" label="发送时间" show-overflow-tooltip />
        <el-table-column prop="content" label="短信内容" width="440">
          <template slot-scope="{row}">
            <el-popover placement="top" width="400" trigger="hover">
              <div class="">
                {{row.content}}
              </div>
              <span slot="reference" class="msg_content">{{row.content}}</span>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column prop="statusDesc" label="发送状态" show-overflow-tooltip />
        <el-table-column prop="principal" label="创建人" show-overflow-tooltip />
        <el-table-column prop="customerReplyContent" label="回复内容" width="440">
          <template slot-scope="{row}">
            <el-popover placement="top" width="400" trigger="hover">
              <div class="" v-html="row.customerReplyContent">
              </div>
              <span slot="reference" class="msg_content">{{row.customerReplyContent}}</span>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column prop="settleRegisterCnt" label="操作" width="80px" fixed="right">
          <template slot-scope="{row}">
            <el-link type="primary" :underline="false" @click="reSend(row)">重发</el-link>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination_list">
        <el-pagination background layout="sizes, total,prev, pager, next, jumper" :total="pageTotal" :page-size="pageSize" :page-sizes="pageSizes" :current-page.sync="pageNumber" @current-change="getList" @size-change="changePageSize" />
      </div>
    </div>
    <!-- 表格 end -->
  </div>
</template>
  
<script>
import { GETSMSSEARCH, SMSRESEND } from "@/http/system";
import { showToast, showModal, deepClone } from "@/common/util";
import { exportExcel } from "@/common/common";
import TabUser from "@/components/user";
import TabHospital from "@/components/hospital";
export default {
  name: "BookPage",
  props: {
    status: {
      type: [String, Number],
      default: "",
    },
  },
  components: {
    TabUser,
    TabHospital,
  },
  data() {
    return {
      formInline: {},
      tableData: [],
      pageTotal: 0,
      pageNumber: 1,
      pageSizes: [10, 20, 50, 100],
      pageSize: 20,
      showDialog: false,
      loading: false,
      bizTypeList: {
        2: "注册短信",
        7: "预约短信",
        8: "活动短信",
      },
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    /** 重置 */
    rest() {
      this.formInline = {};
      this.getList();
    },

    /** 每页展示 */
    changePageSize(e) {
      this.pageSize = e;
      this.getList();
    },

    /** 获取参数 */
    getParams() {
      let oParams = JSON.parse(JSON.stringify(this.formInline));
      let n = oParams.orderTime;

      if (n && n.length > 0) {
        oParams.sDate = n[0];
        oParams.eDate = n[1];
      }
      delete oParams.orderTime;
      oParams.pageSize = this.pageSize;
      oParams.pageNumber = this.pageNumber;
      return oParams;
    },

    /** 获取列表 */
    getList(current) {
      let _this = this;
      let oParams = this.getParams();
      GETSMSSEARCH(oParams).then((res) => {
        let obj = res.data || {};
        _this.tableData = obj.list || [];
        _this.pageTotal = obj.totalElements;
      });
    },

    // 重发
    reSend(row) {
      let _this = this;
      console.log(row);
      showModal({
        message: "确定将该短信重新发送吗？",
        showCancelButton: true,
        type: "warning",
        success: function () {
          SMSRESEND({ id: row.id }).then((res) => {
            if (res.code == 200) {
              showToast({
                message: "发送成功",
                type: "success",
              });
              _this.getList();
            }
          });
        },
      });
    },

    // 格式化用户数据
    showFormatter(row) {
      let o = deepClone(row);
      if (!o) {
        return {};
      }
      o.id = o.clueId;
      o.name = o.customerName;
      o.phone = o.customerPhone;
      return o;
    },

    // 搜索
    onSearch(){
      this.pageNumber = 1;
      this.getList()
    }
  },
};
</script>
  
<style lang="scss" scoped>
@import "@/assets/style/customer/index.scss";
</style>
  